package com.zhangyongyi.carhome.db;

import com.zhangyongyi.carhome.entity.greendao.DaoSession;
import com.zhangyongyi.carhome.entity.greendao.EpisodeList;
import com.zhangyongyi.carhome.entity.greendao.FocusimgList;
import com.zhangyongyi.carhome.entity.greendao.ForumList;
import com.zhangyongyi.carhome.entity.greendao.HotList;
import com.zhangyongyi.carhome.entity.greendao.NewesListEntity;
import com.zhangyongyi.carhome.entity.greendao.PersuaderList;

import java.util.List;

/**
 * Created by dllo on 16/1/17.
 * 操作数据库  增删查
 */
public class DaoHelper {


    private static DaoHelper helper;
    private static DaoSession daoSession;

    private DaoHelper() {

    }

    public static DaoHelper getInstance() {
        if (helper == null) {
            helper = new DaoHelper();
            daoSession = Dao.getDaoSession();
        }
        return helper;
    }

    //删除
    //NewestList
    public void deleteNewestList() {
        daoSession.getNewesListEntityDao().deleteAll();
    }

    //添加
    public void addNewestList(List<NewesListEntity> data) {
        deleteNewestList();
        daoSession.getNewesListEntityDao().insertInTx(data);
    }

    //查询
    public List<NewesListEntity> seacherNewestList() {
        return daoSession.getNewesListEntityDao().loadAll();
    }

    //*
    public void deleteFocusimgList() {
        daoSession.getFocusimgListDao().deleteAll();
    }

    public void addFocusimgList(List<FocusimgList> data) {
        deleteFocusimgList();
        daoSession.getFocusimgListDao().insertInTx(data);
    }

    public List<FocusimgList> seacherFocusimgList() {
        return daoSession.getFocusimgListDao().loadAll();
    }

    //*
    public void deletePersuaderList() {
        daoSession.getPersuaderListDao().deleteAll();
    }

    public void addPersuaderList(List<PersuaderList> data) {
        deletePersuaderList();
        daoSession.getPersuaderListDao().insertInTx(data);

    }

    public List<PersuaderList> seacherPersuaderList() {
        return daoSession.getPersuaderListDao().loadAll();
    }

    //*

    public void deleteForumList() {
        daoSession.getPersuaderListDao().deleteAll();
    }

    public void addForumList(List<ForumList> data) {
        deleteForumList();
        daoSession.getForumListDao().insertInTx(data);

    }

    public List<ForumList> seacherForumList() {
        return daoSession.getForumListDao().loadAll();
    }

    //*

    public void deleteHotList() {
        daoSession.getHotListDao().deleteAll();
    }

    public void addHotList(List<HotList> data) {
        deleteHotList();
        daoSession.getHotListDao().insertInTx(data);

    }

    public List<HotList> seacherHotList() {
        return daoSession.getHotListDao().loadAll();
    }


    //*  EpisodeList


    public void deleteEpisodeList() {
        daoSession.getEpisodeListDao().deleteAll();
    }

    public void addEpisodeList(List<EpisodeList> data) {
        deleteEpisodeList();
        daoSession.getEpisodeListDao().insertInTx(data);
    }

    public List<EpisodeList> seacherEpisodeList() {
        return daoSession.getEpisodeListDao().loadAll();
    }


}
